package com.code.bolg.controller;

import com.code.bolg.bean.Category;
import com.code.bolg.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Category
 *
 * @author  2018-10-12
 */
//@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 新增或编辑
     */
    @PostMapping("/saveOrUpdate")
    public Category save(Category category) {
        return categoryService.save(category);
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    public int delete(int id) {
        return categoryService.deleteById(id);
    }

    /**
     * 查询
     */
    @GetMapping("/find")
    public Category find(int id) {
        Category category = categoryService.findById(id);
        return category;
    }

    /**
     * 分页查询
     */
    @PostMapping("/list")
    public List<Category> list(Category Category,
                       @RequestParam(required = false, defaultValue = "0") int page,
                       @RequestParam(required = false, defaultValue = "10") int size) {
        List<Category> list = categoryService.findAll(Category, page-1==-1?0:page, size);
        return list;
    }

}

